//
//  MyInfosViewController.swift
//  GitOSC-Swift
//
//  Created by 李萍 on 16/1/22.
//  Copyright © 2016年 李萍. All rights reserved.
//

import UIKit
import Kingfisher

class MyInfosViewController: UITableViewController {
    @IBOutlet weak var userPortrait: UIImageView!
    @IBOutlet weak var userNameLabel: UILabel!

    @IBOutlet weak var followingLabel: UILabel!
    @IBOutlet weak var followersLabel: UILabel!
    @IBOutlet weak var starttesLabel: UILabel!
    @IBOutlet weak var watchesLabel: UILabel!
    
    @IBOutlet weak var joinTimeLabel: UILabel!
    @IBOutlet weak var weiboLabel: UILabel!
    @IBOutlet weak var bokeLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let view = UIView.init(frame: CGRectZero)
        self.tableView.tableFooterView = view
        
        self.setContentForMyInfosView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func cancleLogin(sender: AnyObject) {
        let userinfos = UserInfos()
        userinfos.removeUserInfos()
        self.navigationController?.popToRootViewControllerAnimated(true)
        
        print("取消登录")
    }
    
    func setContentForMyInfosView() -> Void {
        let userDefaults = NSUserDefaults.standardUserDefaults()
        
        let portraitURL = userDefaults.valueForKey("portrait") as! String
        let userName = userDefaults.valueForKey("name") as! String
        
        let following = userDefaults.valueForKey("followingCount") as! Int
        let followers = userDefaults.valueForKey("followerCount") as! Int
        let staredes = userDefaults.valueForKey("staredCount") as! Int
        let watchedes = userDefaults.valueForKey("watchedCount") as! Int
        
        let joinTime = userDefaults.valueForKey("create_at") as! String
        let weibo = userDefaults.valueForKey("weibo") as! String
        let blog = userDefaults.valueForKey("blog") as! String
        
        userPortrait.kf_setImageWithURL(NSURL.init(string: "https://git.oschina.net/"+portraitURL)!, placeholderImage: UIImage.init(named: "LoginLogo"))
        userNameLabel.text = userName
        
        followingLabel.text = "Followinf:\(following)"
        followersLabel.text = "Followers:\(followers)"
        starttesLabel.text = "Starred:\(staredes)"
        watchesLabel.text = "Watched:\(watchedes)"
        
        joinTimeLabel.text = "加入时间："+joinTime
        weiboLabel.text = "微博："+weibo
        bokeLabel.text = "博客："+blog
    }
}
